Socket
Socket
Sign inDemoInstall

tinybench

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tinybench

_I'm transitioning to a full-time open source career. Your support would be greatly appreciated πŸ™Œ_ <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/embed/tiers.svg?org=tinyli


Version published
Maintainers
2
Created

What is tinybench?

The tinybench npm package is a lightweight benchmarking tool for JavaScript. It allows developers to measure the performance of their code by running benchmarks and comparing the execution times of different code snippets.

What are tinybench's main functionalities?

Basic Benchmarking

This feature allows you to create a basic benchmark test. You can add multiple tests to the benchmark and run them to measure their performance.

const { Bench } = require('tinybench');

const bench = new Bench();

bench.add('Example Test', () => {
  // Code to benchmark
  for (let i = 0; i < 1000; i++) {}
});

bench.run().then(() => {
  console.log(bench.table());
});

Asynchronous Benchmarking

This feature allows you to benchmark asynchronous code. You can add tests that return promises and the benchmark will wait for them to resolve before measuring their performance.

const { Bench } = require('tinybench');

const bench = new Bench();

bench.add('Async Test', async () => {
  // Asynchronous code to benchmark
  await new Promise(resolve => setTimeout(resolve, 1000));
});

bench.run().then(() => {
  console.log(bench.table());
});

Customizing Benchmark Options

This feature allows you to customize the benchmark options such as the total time to run the benchmark and the number of iterations. This can help in fine-tuning the benchmarking process.

const { Bench } = require('tinybench');

const bench = new Bench({ time: 2000, iterations: 10 });

bench.add('Custom Options Test', () => {
  // Code to benchmark
  for (let i = 0; i < 1000; i++) {}
});

bench.run().then(() => {
  console.log(bench.table());
});

Other packages similar to tinybench

Keywords

FAQs

Package last updated on 02 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc